package com.ssm.dao;

import com.ssm.domain.Folder;
import com.ssm.domain.SysFile;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 文件夹数据操作接口
 */
public interface IFolderDao {
    @Select("select * from sys_folder")
    List<Folder> findAll() throws Exception;

    @Insert("insert into sys_folder(foldername,folderremark) values(#{foldername},#{folderremark})")
    void save(Folder folder) throws Exception;

    @Delete("delete from file_folder where folderid=#{folderId}")
    void deleteFolderfromFile(String folderId);
    @Delete("delete from sys_folder where id=#{folderId}")
    void deleteFolder(String folderId) throws Exception;


    @Select("select * from sys_folder where id=#{folderId}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "foldername", column = "foldername"),
            @Result(property = "folderremark", column = "folderremark"),
            @Result(property = "sysFiles",column = "id",javaType = java.util.List.class,many = @Many(select = "com.ssm.dao.IFileDao.findFileByFolderId"))
    })
    Folder findById(String folderId) throws Exception;

    @Select("select * from sys_file where id not in (select fileid from file_folder where folderid=#{folderId})")
    List<SysFile> findOtherFiles(String folderId);

    @Insert("insert into file_folder(folderId,fileId) values(#{folderId},#{fileId})")
    void addFileToFolder(@Param("folderId") String folderId, @Param("fileId")String fileId);

    @Select("select * from sys_folder where id in (select folderId from file_folder where fileId =#{fileId})")
    List<Folder> findFolderByFileId(String fileId) throws Exception;

}
